<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<base href="<%=basePath%>" />
<title>Index</title>

<jsp:include page="../header.jsp"></jsp:include>

<script type="text/javascript">
	$(function() {
		$("#addProject").click(function() {
			showProjectPanel();
		});

        $('.selectpicker').selectpicker();

        $(".form_datetime").datepicker({
            format: "yyyy-mm-dd",
            autoclose: true,
        });
    });

    function showProjectPanel(id, name, startDate, shejiCompanyId, shigongCompanyId, jianliCompanyId, shenjiCompanyId, zhaobiaoCompanyId, fund) {
        $("#projectPanel [name='project.id']").val(id);
        $("#projectPanel [name='project.name']").val(name);
        $("#projectPanel [name='project.startDate']").val(startDate);
        $("#projectPanel [name='project.shejiCompany.id']").selectpicker('val', shejiCompanyId);
        $("#projectPanel [name='project.shigongCompanyId.id']").selectpicker('val', shigongCompanyId);
        $("#projectPanel [name='project.jianliCompanyId.id']").selectpicker('val', jianliCompanyId);
        $("#projectPanel [name='project.shenjiCompanyId.id']").selectpicker('val', shenjiCompanyId);
        $("#projectPanel [name='project.zhaobiaoCompanyId.id']").selectpicker('val', zhaobiaoCompanyId);
        $("#projectPanel [name='project.fund']").val(fund);
		$("#projectPanel").modal();
	}
</script>
</head>
<body>
	<jsp:include page="../top.jsp"></jsp:include>

	<div class="container theme-showcase" role="main">

		<div class="alert alert-success">
			<h2>项目列表</h2>
		</div>
		<div class="well">
			<div>
				<a class="btn btn-success" id="addProject">添加项目</a>
			</div>
		</div>

		<div id="projectList">
			<table class="table table-hover">
				<tr>
					<th>项目名称</th>
					<th>开始日期</th>
					<th>设计单位</th>
					<th>施工单位</th>
					<th>监理单位</th>
					<th>审计单位</th>
					<th>招标单位</th>
					<th>总金额</th>
					<th>支付历史</th>
					<th>档案管理</th>
					<th>操作</th>
				</tr>
				<s:iterator value="projectList" var="d">
					<tr>
						<td><s:property value="#d.name" /></td>
						<td><s:date name="#d.startDate" format="yyyy-MM-dd"/></td>
						<td><s:property value="#d.shejiCompany.name"/></td>
						<td><s:property value="#d.shigongCompany.name"/></td>
						<td><s:property value="#d.jianliCompany.name"/></td>
						<td><s:property value="#d.shenjiCompany.name"/></td>
						<td><s:property value="#d.zhaobiaoCompany.name"/></td>
						<td><s:property value="#d.fund"/></td>
						<td><a href="payment/listPayment?project.id=<s:property value='#d.id'/>" class="btn btn-primary">支付历史</a></td>
						<td><a href="attachment/listAttachment?project.id=<s:property value='#d.id'/>" class="btn btn-primary">档案管理</a></td>
						<td>
							<div class="btn-group" role="group">
								<button type="button" class="btn btn-primary dropdown-toggle"
									data-toggle="dropdown" aria-haspopup="true"
									aria-expanded="false">
									操作 <span class="caret"></span>
								</button>
								<ul class="dropdown-menu">
									<li><a href="javascript:void(0);"
										onclick="showProjectPanel('<s:property value="#d.id"/>','<s:property value="#d.name"/>','<s:date name="#d.startDate" format="yyyy-MM-dd"/>','<s:property value="#d.shejiCompany.id"/>','<s:property value="#d.shigongCompany.id"/>','<s:property value="#d.jianliCompany.id"/>','<s:property value="#d.shenjiCompany.id"/>','<s:property value="#d.zhaobiaoCompany.id"/>','<s:property value="#d.fund"/>');">修改</a></li>
									<li role="separator" class="divider"></li>
									<li><a
										href="project/deleteProject?project.id=<s:property value='#d.id'/>&company.id=<s:property value='company.id'/>" onclick="return confirm('确认删除吗？');">删除</a></li>
								</ul>
							</div>
						</td>
					</tr>
				</s:iterator>
			</table>
		</div>
		<div class="modal fade" id="projectPanel" tabindex="-1" role="dialog"
			aria-labelledby="myModalLabel" aria-hidden="true">
			<form action="project/saveProject" method="post">
				<input type="hidden" name="project.id" />
				<s:hidden name="company.id"/>
				<div class="modal-dialog">
					<div class="modal-content">
						<div class="modal-header">
							<button type="button" class="close" data-dismiss="modal"
								aria-label="Close">
								<span aria-hidden="true">&times;</span>
							</button>
							<h4 class="modal-title">项目信息</h4>
						</div>
						<div class="modal-body">
							<h4>
								<ul >
									<li class="list-group-item"><label> 项目名称 </label> <input
										type="text" class="form-control" name="project.name"
										placeholder="项目名称" /></li>
									<li class="list-group-item"><label> 开始日期 </label>
										<div class="input-append date form_datetime">
											<input size="16" type="text" class="form-control" value="" name="project.startDate"
												   placeholder="开始日期" readonly>
											<span class="add-on"><i class="icon-th"></i></span>
										</div>
									</li>
									<li class="list-group-item"><label> 设计单位 </label><br/>
										<select class="selectpicker" name="project.shejiCompany.id" data-live-search="true">
											<s:iterator value="companyMap[@com.bnds.pms.model.Company$Type@SHEJI]" var="c">
												<option value="<s:property value='#c.id'/>"><s:property value="#c.name" /></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 施工单位 </label><br/>
										<select class="selectpicker" name="project.shigongCompany.id" data-live-search="true">
											<s:iterator value="companyMap[@com.bnds.pms.model.Company$Type@SHIGONG]" var="c">
												<option value="<s:property value='#c.id'/>"><s:property value="#c.name" /></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 监理单位 </label><br/>
										<select class="selectpicker" name="project.jianliCompany.id" data-live-search="true">
											<s:iterator value="companyMap[@com.bnds.pms.model.Company$Type@JIANLI]" var="c">
												<option value="<s:property value='#c.id'/>"><s:property value="#c.name" /></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 审计单位 </label><br/>
										<select class="selectpicker" name="project.shenjiCompany.id" data-live-search="true">
											<s:iterator value="companyMap[@com.bnds.pms.model.Company$Type@SHENJI]" var="c">
												<option value="<s:property value='#c.id'/>"><s:property value="#c.name" /></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 招标单位 </label><br/>
										<select class="selectpicker" name="project.zhaobiaoCompany.id" data-live-search="true">
											<s:iterator value="companyMap[@com.bnds.pms.model.Company$Type@ZHAOBIAO]" var="c">
												<option value="<s:property value='#c.id'/>"><s:property value="#c.name" /></option>
											</s:iterator>
										</select>
									</li>
									<li class="list-group-item"><label> 总金额 </label> <input
										type="number" class="form-control" name="project.fund"
										placeholder="总金额" /></li>
								</ul>
							</h4>
						</div>
						<div class="modal-footer">
							<button type="submit" class="btn btn-success">保存</button>
							<button type="button" class="btn btn-default"
								data-dismiss="modal">取消</button>
						</div>
					</div>
				</div>
			</form>
		</div>
		</div>
	</div>
	<jsp:include page="../footer.jsp"></jsp:include>
</body>
</html>
